<template>
<div class="body">
  <div class="center">
    <div class="head">
      <h2>校园疫情防控</h2>
    </div>
    <div class="form">
      <el-form label-position="left" >
        <el-form-item label="用户名">
          <el-input v-model="form.username" ></el-input>
        </el-form-item>

        <el-form-item label="密码 &nbsp&nbsp">
          <el-input v-model="form.password" show-password></el-input>
        </el-form-item>
        <el-radio-group v-model="form.radio">
          <el-radio :label="1">学生</el-radio>
          <el-radio :label="2">教师</el-radio>
          <el-radio :label="3">管理员</el-radio>
        </el-radio-group>

        <div>
        <el-button type="primary" @click="login">登录</el-button>
        </div>

      </el-form>

    </div>
  </div>
</div>
</template>

<script>
  import axios from 'axios'
  export default {

    name: "login",
    data(){
      return{
        LoginData:[],
        form:{
          username:'',
          password:'',
          radio:''
        }
      }
    },
    methods:{
      login(){
        axios.post('http://localhost:3000/users/login',{
          username:this.form.username,
          password:this.form.password,
          type:this.form.radio
        }).then(res=>{
          this.LoginData=res.data.LoginData
          window.localStorage.setItem("token",res.data.jwt_token)
          this.$router.push({name:'Home'})


        }).catch(err=>{
          console.log(err)
          this.open()
        })
        },
      open(){
        this.$message('用户名或密码输入错误');
      },

      }


  }
</script>

<style scoped lang="less">
  .body{
    display: flex;
    justify-content: center;
    align-items: center;
    height:500px;
  }
  .center{


    width: 500px;
    height: 300px;

  }
</style>
